package com.ruoyi.shopping.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shopping.domain.CommodityCategory;
import com.ruoyi.shopping.service.ICommodityCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品种类管理Controller
 * 
 * @author fxy
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/shopping/commodityCategory")
public class CommodityCategoryController extends BaseController
{
    @Autowired
    private ICommodityCategoryService commodityCategoryService;

    /**
     * 查询商品种类管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityCategory:list')")
    @GetMapping("/list")
    public AjaxResult list(CommodityCategory commodityCategory)
    {
        List<CommodityCategory> list = commodityCategoryService.selectCommodityCategoryList(commodityCategory);
        return success(list);
    }

    /**
     * 导出商品种类管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityCategory:export')")
    @Log(title = "商品种类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommodityCategory commodityCategory)
    {
        List<CommodityCategory> list = commodityCategoryService.selectCommodityCategoryList(commodityCategory);
        ExcelUtil<CommodityCategory> util = new ExcelUtil<CommodityCategory>(CommodityCategory.class);
        util.exportExcel(response, list, "商品种类管理数据");
    }

    /**
     * 获取商品种类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commodityCategoryService.selectCommodityCategoryById(id));
    }

    /**
     * 新增商品种类管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityCategory:add')")
    @Log(title = "商品种类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommodityCategory commodityCategory)
    {
        return toAjax(commodityCategoryService.insertCommodityCategory(commodityCategory));
    }

    /**
     * 修改商品种类管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityCategory:edit')")
    @Log(title = "商品种类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommodityCategory commodityCategory)
    {
        return toAjax(commodityCategoryService.updateCommodityCategory(commodityCategory));
    }

    /**
     * 删除商品种类管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:commodityCategory:remove')")
    @Log(title = "商品种类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commodityCategoryService.deleteCommodityCategoryByIds(ids));
    }
}
